package com.yunpai.thread;

/**
 * 线程的优先级
 */
public class PriorityThread extends Thread {

    @Override
    public void run() {
        //设置分线程名称
        setName("分线程");
        //设置优先级
        setPriority(1);
        for (int i = 0; i < 10; i++) {
            System.out.println(getName() + "第" + i + "次");
        }
    }

    public static void main(String[] args) {
        PriorityThread priorityThread = new PriorityThread();
        priorityThread.start();
        //设置主线程名称
        Thread.currentThread().setName("主线程");
        //设置优先级
        Thread.currentThread().setPriority(10);

        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName() + "第" + i + "次");
        }
    }
}
